package com.xsp.eduservice.controller;


import com.xsp.eduservice.entity.subject.OneSubject;
import com.xsp.eduservice.service.EduSubjectService;
import com.xsp.commonutils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-01-08
 */
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {

    @Autowired
    EduSubjectService eduSubjectService;

    @ApiOperation("Excel批量导入")
    @PostMapping("/addSubject")
    //导入课程分类
    //MultipartFile：文件参数
    public R addSubject(MultipartFile file){
        //由于实现EasyExcel的读，需要创建listener类(SubjectExcelListener)
        //listener类中需要调用EduSubjectService内的方法，listener类又不能交给spring的IOC管理(不能加注解)
        //因此我们在listener类中添加了有参构造，用来传入外面的EduSubjectService
        eduSubjectService.importSubjectData(file,this.eduSubjectService);
        return R.ok();
    }

    //获取所有课程分类(一级、二级)
    @GetMapping("getAllSubject")
    public R getAllSubject(){
        List<OneSubject> list = eduSubjectService.getAllOneTwoSubject();
        return R.ok().data("list",list);
    }

}

